/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.util.regex.Pattern;
import java.util.regex.Matcher;

;

/**
 * 
 * @author Lerta-D
 */
public class Validator {

	private Matcher mat;
	private Pattern pat;

	public Validator() {
	}

	public boolean validateData(String dato, String expression) {
		if (!validateObject(dato)) {
			return false;
		} else {
			this.pat = Pattern.compile(expression);
			this.mat = pat.matcher(dato);
			if (mat.matches()) {
				return true;
			} else {
				return false;
			}
		}
	}

	public boolean isNumber(String dato) {
		return validateData(dato, "\\d+");
	}

	public boolean isDouble(String dato) {
		return true;
	}

	public boolean isEmail(String dato) {
		return validateData(
				dato,
				"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
	}

	public boolean isAlfa(String dato) {
		return validateData(dato, "\\w+");
	}

	public boolean isValidWord(String dato) {
		return validateData(dato, "^([A-Za-z]+ ?)*$");
	}

	public boolean isOneWord(String dato) {
		return validateData(dato, "\\w+");
	}

	public boolean validateObject(String obj) {
		if (obj.isEmpty() || obj.equals(null))
			return false;
		return true;
	}
}
